﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Medianamik.Core.Mail;
using Medianamik.Core.Security;

namespace Medianamik.UI.Web
{
    public partial class ModifyPasswordWindow : BasePage
    {
        #region Events

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void cvOldPassword_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = Membership.ValidateUser(User.Identity.Name, args.Value);
        }

        protected void cvPasswordStrength_ServerValidate(object source, ServerValidateEventArgs args)
        {
            PasswordValidator validator = new PasswordValidator(Membership.Provider);
            args.IsValid = validator.ValidatePassword(txtNewPassword.Text) == PasswordValidationResult.Success;
                        
        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            if (IsValid
                && MedianamikUser.ChangePassword(txtOldPassword.Text, txtNewPassword.Text))
            {
                phrConfirmation.Visible = true;
                phrMain.Visible = false;
                //Evoyer le courriel
                new MailManager().SendPasswordChangedConfirmationMessage(Membership.GetUser(), this.CurrentUICulture, txtNewPassword.Text, Context);
            }
            else
            {
                phrConfirmation.Visible = false;
                phrMain.Visible = true;
            }
        }

        #endregion

        #region Properties


        #endregion
    }
}
